using System;
using System.Data;
using System.Data.SqlClient;
using NCS.Library;
namespace NCS.Module.CMS.Library.ZoneType
{
    public class Portal_ZoneTypeDB
    {
        public static DataTable GetAll()
        {
            DataTable retVal = null;
            SqlConnection dbConn = new SqlConnection(AppEnv.ConnectionString);
            SqlCommand dbCmd = new SqlCommand("Portal_ZoneType_GetAll", dbConn);
            dbCmd.CommandType = CommandType.StoredProcedure;
            try
            {
                retVal = new DataTable();
                SqlDataAdapter da = new SqlDataAdapter(dbCmd);
                da.Fill(retVal);
            }
            finally
            {
                dbConn.Close();
            }
            return retVal;
        }
        public static DataTable GetAll(int portalid)
        {
            DataTable retVal = null;
            SqlConnection dbConn = new SqlConnection(AppEnv.ConnectionString);
            SqlCommand dbCmd = new SqlCommand("Portal_ZoneType_GetAllByPoratlID", dbConn);
            dbCmd.CommandType = CommandType.StoredProcedure;
            dbCmd.Parameters.AddWithValue("@PortalID", portalid);
            try
            {
                retVal = new DataTable();
                SqlDataAdapter da = new SqlDataAdapter(dbCmd);
                da.Fill(retVal);
            }
            finally
            {
                dbConn.Close();
            }
            return retVal;
        }
        public static void Delete(int _iD)
        {
            SqlConnection dbConn = new SqlConnection(AppEnv.ConnectionString);
            SqlCommand dbCmd = new SqlCommand("Portal_ZoneType_Delete", dbConn);
            dbCmd.CommandType = CommandType.StoredProcedure;
            dbCmd.Parameters.Add("@ID", _iD);
            try
            {
                dbConn.Open();
                dbCmd.ExecuteNonQuery();
            }
            finally
            {
                dbConn.Close();
            }
        }
        public static int Insert(Portal_ZoneTypeInfo _portal_ZoneTypeInfo)
        {
            SqlConnection dbConn = new SqlConnection(AppEnv.ConnectionString);
            SqlCommand dbCmd = new SqlCommand("Portal_ZoneType_Insert", dbConn);
            dbCmd.CommandType = CommandType.StoredProcedure;
            dbCmd.Parameters.Add("@PortalID", _portal_ZoneTypeInfo.PortalID);
            dbCmd.Parameters.Add("@TypeName", _portal_ZoneTypeInfo.TypeName);
            dbCmd.Parameters.Add("@TypeValue", _portal_ZoneTypeInfo.TypeValue);
            dbCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int).Direction = ParameterDirection.ReturnValue;
            try
            {
                dbConn.Open();
                dbCmd.ExecuteNonQuery();
                return (int)dbCmd.Parameters["@RETURN_VALUE"].Value;
            }
            finally
            {
                dbConn.Close();
            }
        }

        public static void Update(Portal_ZoneTypeInfo _portal_ZoneTypeInfo)
        {
            SqlConnection dbConn = new SqlConnection(AppEnv.ConnectionString);
            SqlCommand dbCmd = new SqlCommand("Portal_ZoneType_Update", dbConn);
            dbCmd.CommandType = CommandType.StoredProcedure;
            dbCmd.Parameters.Add("@ID", _portal_ZoneTypeInfo.ID);
            dbCmd.Parameters.Add("@PortalID", _portal_ZoneTypeInfo.PortalID);
            dbCmd.Parameters.Add("@TypeName", _portal_ZoneTypeInfo.TypeName);
            dbCmd.Parameters.Add("@TypeValue", _portal_ZoneTypeInfo.TypeValue);
            try
            {
                dbConn.Open();
                dbCmd.ExecuteNonQuery();
            }
            finally
            {
                dbConn.Close();
            }
        }

        public static Portal_ZoneTypeInfo GetInfo(int _iD)
        {
            Portal_ZoneTypeInfo retVal = null;
            SqlConnection dbConn = new SqlConnection(AppEnv.ConnectionString);
            SqlCommand dbCmd = new SqlCommand("Portal_ZoneType_GetInfo", dbConn);
            dbCmd.CommandType = CommandType.StoredProcedure;
            dbCmd.Parameters.Add("@ID", _iD);
            try
            {
                dbConn.Open();
                SqlDataReader dr = dbCmd.ExecuteReader();
                if (dr.Read())
                {
                    retVal = new Portal_ZoneTypeInfo();
                    retVal.ID = Convert.ToInt32(dr["ID"]);
                    retVal.PortalID = Convert.ToInt32(dr["PortalID"]);
                    retVal.TypeName = Convert.ToString(dr["TypeName"]);
                    retVal.TypeValue = Convert.ToInt32(dr["TypeValue"]);
                }
                if (dr != null) dr.Close();
            }
            finally
            {
                dbConn.Close();
            }
            return retVal;
        }

    }
}
